using System;
using System.IO;

namespace Pronghorn.Core
{
	public class JavaScriptTag : FilesTagBase
	{
		private const string SCRIPT_TYPE = "text/javascript";

		public JavaScriptTag(string code)
			: base(code)
		{
			ScriptType = SCRIPT_TYPE;
		}

		public JavaScriptTag(Uri pathToFile)
			: base(pathToFile)
		{
			ScriptType = SCRIPT_TYPE;
		}

		protected override void RenderInlineTag(TextWriter writer)
		{
			if (_code.Length == 0) return;
			writer.WriteLine(string.Format("<script type=\"{0}\">",ScriptType));
			writer.WriteLine(_code);
			writer.WriteLine("</script>");
		}

		protected override void RenderTagFromFile(TextWriter writer)
		{
			writer.WriteLine(string.Format("<script type=\"{0}\" src=\"{1}\"></script>", ScriptType, _pathToFile));
		}
	}
}